
$(document).ready(function() {
    
    $("#a-upload").click(function(){
        $('#dialog-upload').html('<h1>Imagen de Perfil</h1>'+
            '<form id = "form-upload"  method="POST" enctype="multipart/form-data" action="uploadphoto">'+
            'Por favor, seleccione la imagen a cargar s'+
            '<br><input id="file_image" type="file" name="fichero">'+           
            '</form>');
        $( "#dialog-upload" ).dialog("open");
    });
    
    $("#dialog-upload").submit(function() {
        var val = $("#file_image").val();

        switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
            case 'gif': case 'jpg': case 'png':
                return true;
                break;
            default:
                $("#file_image").val('');
                // error message here
                return false;
                break;
        }
    });
});

$(function() {
    $( "#dialog:ui-dialog" ).dialog( "destroy" );		    
		
    $( "#dialog-upload" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Subir Imagen": function() {
                $('#form-upload').submit();
            },
            "Cancel": function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            $('#dialog-upload').html('');
        }
    });

    $( "#dialog-upload" )
    .button()
    .click(function() {
        
        $( "#dialog-form" ).dialog( "open" );
    });
});


	